/***************************************************************************//**
 * @file GUI/PFD_ADI.h
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2013 Marek M. Cel
 *
 * This file is part of MScSim. You can redistribute and modify it under
 * the terms of GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Further information about the GNU General Public License can also be found
 * on the world wide web at http://www.gnu.org.
 ******************************************************************************/
#ifndef PFD_ADI_H
#define PFD_ADI_H

////////////////////////////////////////////////////////////////////////////////

#include <QGraphicsView>
#include <QGraphicsSvgItem>

////////////////////////////////////////////////////////////////////////////////

class PFD_ADI
{
public:

    /** */
    PFD_ADI( QGraphicsScene *scene );

    /** */
    void init( float scaleX, float scaleY );

    /** */
    void update( float scaleX, float scaleY );

    /** @param roll angle [deg] */
    void setRoll( float roll );

    /** @param pitch angle [deg] */
    void setPitch( float pitch );

    /**
     * @param angle of attack [deg]
     * @param angle of sideslip [deg] */
    void setFlightPathMarker( float aoa, float sideslip );

    /** @param normalized slip or skid (range from -1.0 to 1.0) */
    void setSlipSkid( float slipSkid );

    /**
     * @param normalized turn rate (range from -1.0 to 1.0),
     * hash marks positions are set to be -0.5 and 0.5 */
    void setTurnRate( float turnRate );

private:

    QGraphicsScene *m_scene;    ///< graphics scene

    QGraphicsSvgItem  *m_itemBack;      ///< background
    QGraphicsSvgItem  *m_itemLadd;      ///< pitch ladder
    QGraphicsSvgItem  *m_itemRoll;      ///< roll mask
    QGraphicsSvgItem  *m_itemSlip;      ///< slip indicator
    QGraphicsSvgItem  *m_itemTurn;      ///< turn rate indicator
    QGraphicsSvgItem  *m_itemPath;      ///< flight path indicator
    QGraphicsSvgItem  *m_itemMark;      ///< flight path indicator invalid mark
    QGraphicsSvgItem  *m_itemMask;      ///< adi mask

    float m_roll;           ///< [deg]
    float m_pitch;          ///< [deg]
    float m_angleOfAttack;  ///< [deg]
    float m_sideslipAngle;  ///< [deg]
    float m_slipSkid;       ///< -1.0 ... 1.0
    float m_turnRate;       ///< -1.0 ... 1.0

    bool m_pathValid;   ///<

    float m_laddDeltaX_new;
    float m_laddDeltaX_old;
    float m_laddBackDeltaX_new;
    float m_laddBackDeltaX_old;
    float m_laddBackDeltaY_new;
    float m_laddBackDeltaY_old;
    float m_laddDeltaY_new;
    float m_laddDeltaY_old;
    float m_slipDeltaX_new;
    float m_slipDeltaX_old;
    float m_slipDeltaY_new;
    float m_slipDeltaY_old;
    float m_turnDeltaX_new;
    float m_turnDeltaX_old;
    float m_pathDeltaX_new;
    float m_pathDeltaX_old;
    float m_pathDeltaY_new;
    float m_pathDeltaY_old;
    float m_markDeltaX_new;
    float m_markDeltaX_old;
    float m_markDeltaY_new;
    float m_markDeltaY_old;

    float m_scaleX;
    float m_scaleY;

    const float m_originalPixPerDeg;    ///< [px/deg] pixels to move pitch ladder due to 1 deg pitch
    const float m_deltaLaddBack_max;    ///< [px] max pitch ladder background deflection
    const float m_deltaLaddBack_min;    ///< [px] min pitch ladder background deflection
    const float m_maxSlipDeflection;    ///< [px] max slip indicator deflection
    const float m_maxTurnDeflection;    ///< [px] max turn indicator deflection

    QPointF m_originalAdiCtr;
    QPointF m_originalBackPos;
    QPointF m_originalLaddPos;
    QPointF m_originalRollPos;
    QPointF m_originalSlipPos;
    QPointF m_originalTurnPos;
    QPointF m_originalPathPos;

    const int m_backZ;
    const int m_laddZ;
    const int m_rollZ;
    const int m_slipZ;
    const int m_pathZ;
    const int m_maskZ;
    const int m_turnZ;

    /** */
    void reset();

    /** */
    void updateLadd( float delta, float sinRoll, float cosRoll );

    /** */
    void updateLaddBack( float delta, float sinRoll, float cosRoll );

    /** */
    void updateRoll();

    /** */
    void updateSlipSkid( float sinRoll, float cosRoll );

    /** */
    void updateTurnRate();

    /** */
    void updateFlightPath();
};

////////////////////////////////////////////////////////////////////////////////

#endif // PFD_ADI_H
